-- cure_hp2
-- create by cheny3
-- 技能: 恢复自身百分比生命值

return {
    apply = function(source, target, skillId, round, para, extra)
        local hp = 0;

        -- 被恢复怪物最大生命（只恢复基础的部分）
        local sourceHp = math.max(source:query("hp"), 0);
        local maxHp = source:queryAttrib("max_hp");

        if para[2] == 1 then
            -- 1. 威力
            local force = para[1];
            -- 2. 施展方的最大生命值
            -- 3. 作用
            hp = math.modf(maxHp * force / 1000);
        elseif para[2] == 2 then
            hp = para[1];
        end

        -- 不超过上限
        hp = math.min((maxHp - sourceHp), hp);

        -- 确保值不会小于0
        hp = math.max(hp, 0);

        CombatM.receiveCure(source, source, hp);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        local ret = {};

        for i = 1, #arr do
            table.insert(ret, tonumber(arr[i]));
        end
        return ret;
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local force = para[1];
        if para[2] == 1 then
            desc = string.gsub(desc, "{number}", tostring(force / 10).."%%" );
        elseif para[2] == 2 then
            desc = string.gsub(desc, "{number}", force );
        end
        return desc;
    end,
}
